/*
 * Created by SharpDevelop.
 * User: darius.damalakas
 * Date: 2008-12-10
 * Time: 17:29
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using NUnit.Framework;
using SourceGrid;
using System.ComponentModel;
using System.Data;
using System.Windows.Forms;
using SourceGrid.Selection;
using SourceGrid.Tests.Selection;

namespace SourceGrid.Tests.Performance
{
	public interface IPerformanceCounter : IDisposable
	{
		int GetSeconds();
	}
	
	public class PerformanceCounter : IDisposable, IPerformanceCounter
	{
		private DateTime m_start = DateTime.MinValue;
		
		public PerformanceCounter()
		{
			this.m_start = DateTime.Now;
		}
		
		public int GetSeconds()
		{
			TimeSpan span = DateTime.Now - m_start;
			return span.Seconds;
		}
		
		public void Dispose()
		{
		}
	}
	
	[TestFixture]
	public class TestRangeRegion_Performance
	{
		[Test]
		public void GetRowsIndex_Performance()
		{
			// this test, sadly, tests nothing
			// remove it 
			RangeRegion region = new RangeRegion(new Range(0, 0, 10000, 5000));
			
			using (IPerformanceCounter counter = new PerformanceCounter())
			{
				region.GetRowsIndex();
				Console.WriteLine(string.Format(
					"Test executed in {0} seconds", counter.GetSeconds()));
			}
		}
	}
	
	
	[TestFixture]
	public class TestRowSelection_Performance
	{
		[Test]
		public void GetSelectionRegion_GetRows_Index_Performance()
		{
			// select range:
			// * from row 1 to 2000
			// Print out how long in seconds that function takes to execute
			
			// The tests take seconds to execute
			// 6 seconds, 2008-12-11, AMD Athlon 64 X2 dual machine
			// 0 seconds, 2008-12-11, AMD Athlon 64 X2 dual machine
			
			Grid grid = new TestRowSelectionHelper().CreateGridWithRows(2000);

			grid.Selection.SelectRange(new Range(0, 0, 1999, 1), true);
			
			using (IPerformanceCounter counter = new PerformanceCounter())
			{
				grid.Selection.GetSelectionRegion().GetRowsIndex();
				
				Console.WriteLine(string.Format(
					"Test executed in {0} seconds", counter.GetSeconds()));
			}
		}
	}
}
